﻿using System.Drawing;
using pub.CmdUI.Cmd;
using pub.CmdUI.UI.Control;
using pub.NET20Fix;

namespace todo.Ribbon.CmdUI
{
    public class RibbonGalleryUI : IItemsControlUI
    {
        private RibbonGalleryControl _gallery;
        private Action _triggerCallback;
        private int? _clickedIndex;

        public RibbonGalleryUI(RibbonGalleryControl gallery)
        {
            _gallery = gallery;
            gallery.OnSelect += gallery_OnSelect;
        }

        private void gallery_OnSelect(int index)
        {
            _clickedIndex = index;
            if (_triggerCallback != null)
            {
                _triggerCallback();
            }
        }

        public Action TriggerCallback
        {
            set { _triggerCallback = value; }
        }

        public Bitmap Icon
        {
            set
            {
                //?
            }
        }

        public string Label
        {
            set
            {
                //?
            }
        }

        public string Tooltip
        {
            set
            {
                //?
            }
        }

        public void Update(ICmd cmd)
        {
            var state = cmd.State as IItemsCmdState;
            _gallery.SelectedIndex = state.SelectedIndex;

            _gallery.Enabled = cmd.State.Enabled;
        }

        public int? SelectedItemIndex
        {
            get { return _clickedIndex; }
        }
    }
}